﻿package blob
{
    import blob.tutorialAnimations.*;
    import org.flixel.*;

    public class PauseMenu extends FlxGroup
    {
        private var Bg:Class;
        private var Bjump:Class;
        private var Bwalk:Class;
        private var Sswitch:Class;
        public var showing:Boolean;
        private var _display:Boolean;
        private var _finishCallback:Function;
        private var _pauseTime:Number;

        public function PauseMenu()
        {
            this.Bg = PauseMenu_Bg;
            this.Bjump = PauseMenu_Bjump;
            this.Bwalk = PauseMenu_Bwalk;
            this.Sswitch = PauseMenu_Sswitch;
            var _loc_1:* = new FlxSprite(0, 0, this.Bg);
            add(_loc_1);
            var _loc_2:Number = 420;
            var _loc_3:Number = 200;
            var _loc_4:Number = 41;
            var _loc_5:* = 2 * _loc_4;
            var _loc_6:* = 3 * _loc_4;
            var _loc_7:* = new walkTutorial(_loc_2, _loc_3, false);
            add(_loc_7);
            var _loc_8:* = new FlxText(_loc_7.x + 5, _loc_7.y + _loc_5, 250, "Left");
            new FlxText(_loc_7.x + 5, _loc_7.y + _loc_5, 250, "Left").setFormat(null, 12);
            add(_loc_8);
            var _loc_9:* = _loc_2 + 70;
            var _loc_10:* = _loc_3 - 90;
            var _loc_11:* = new jumpTutorial(_loc_9, _loc_10, true);
            add(_loc_11);
            var _loc_12:* = new FlxText(_loc_11.x, _loc_11.y + _loc_6, 250, "Jump");
            new FlxText(_loc_11.x, _loc_11.y + _loc_6, 250, "Jump").setFormat(null, 12);
            add(_loc_12);
            var _loc_13:* = new switchTutorial(_loc_9, _loc_10 + _loc_6 + 20, true);
            add(_loc_13);
            var _loc_14:* = new FlxText(_loc_13.x - 29, _loc_13.y + _loc_5, 250, "Activate Switch");
            new FlxText(_loc_13.x - 29, _loc_13.y + _loc_5, 250, "Activate Switch").setFormat(null, 12);
            add(_loc_14);
            var _loc_15:* = new walkTutorial(_loc_2 + 140, _loc_3, true);
            add(_loc_15);
            var _loc_16:* = new FlxText(_loc_15.x + 2, _loc_15.y + _loc_5, 250, "Right");
            new FlxText(_loc_15.x + 2, _loc_15.y + _loc_5, 250, "Right").setFormat(null, 12);
            add(_loc_16);
            var _loc_17:* = new tabTutorial(_loc_2 - 200, _loc_10 + 30, true);
            add(_loc_17);
            var _loc_18:* = new FlxText(_loc_17.x - 17, _loc_17.y + _loc_5, 250, "Switch Character");
            new FlxText(_loc_17.x - 17, _loc_17.y + _loc_5, 250, "Switch Character").setFormat(null, 12);
            add(_loc_18);
            var _loc_19:* = new splitTutorial(_loc_2 - 200, _loc_3 + 35, true);
            add(_loc_19);
            var _loc_20:* = new FlxText(_loc_19.x + _loc_4 / 2, _loc_19.y + _loc_6, 250, "Split and Merge");
            new FlxText(_loc_19.x + _loc_4 / 2, _loc_19.y + _loc_6, 250, "Split and Merge").setFormat(null, 12);
            add(_loc_20);
            var _loc_21:* = new FlxText(0, 420, 800, "Resume: P" + "\nRestart: \"R\"" + "\nLevel Select: \"M\"");
            new FlxText(0, 420, 800, "Resume: P" + "\nRestart: \"R\"" + "\nLevel Select: \"M\"").setFormat(null, 18, 16777215, "center");
            add(_loc_21);
            var _loc_22:* = new FlxText(0, 25, 800, "Pause Menu");
            new FlxText(0, 25, 800, "Pause Menu").setFormat(null, 28, 16777215, "center");
            add(_loc_22);
            return;
        }// end function

        public function showPaused() : void
        {
            this._display = true;
            this.showing = true;
            this._pauseTime = 0;
            return;
        }// end function

        override public function update() : void
        {
            if (this._display)
            {
                this._pauseTime = this._pauseTime + FlxG.elapsed;
                if (FlxG.keys.justPressed("P") && this._pauseTime >= 0.1)
                {
                    this.killPause();
                    if (this._finishCallback != null)
                    {
                        this._finishCallback();
                    }
                }
                else if (FlxG.keys.justPressed("R"))
                {
                    this.killPause();
                    FlxG.resetState();
                }
                else if (FlxG.keys.justPressed("M"))
                {
                    this.killPause();
                    FlxG.switchState(new GameMenu());
                }
                else
                {
                    this.showing = true;
                    this._display = true;
                }
                super.update();
            }
            return;
        }// end function

        public function set finishCallback(param1:Function) : void
        {
            this._finishCallback = param1;
            return;
        }// end function

        private function killPause() : void
        {
            this.kill();
            this.exists = false;
            this.showing = false;
            this._display = false;
            this._pauseTime = Number.MIN_VALUE;
            return;
        }// end function

    }
}
